﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;

namespace Mvc.RazorTools.Glyphicons
{
	/// <summary>
	/// Provides a set of extension methods for the System.Web.Mvc.HtmlHelper class. These extension
	/// methods are referenced in the razor view using the @Html keyword.
	/// </summary>
	public static class HtmlExtensions
	{
		/// <summary>
		/// Inserts the specified Glyphicon into the view.
		/// </summary>
		/// <param name="html">The view's current HtmlHelper instance.</param>
		/// <param name="item">The icon to be displayed. This can be a custom instance or one of the
		/// predefined icons in GlyphiconsSet (for example, to display the star icon use
		/// GlyphiconsSet.Star).</param>
		/// <param name="classAttributes">The custom attributes to be added to the icon.</param>
		/// <returns></returns>
		public static MvcHtmlString Glyphicons(this HtmlHelper html, Glyphicon item, params string[] classAttributes)
		{
			if (html == null) throw new ArgumentNullException("html");
			if (item == null) throw new ArgumentNullException("item");
			Glyphicon font = (Glyphicon)item.Clone();
			font.MergeClassAttributes(classAttributes);
			return font.Html;
		}

		/// <summary>
		/// Inserts the specified Glyphicon into the view.
		/// </summary>
		/// <param name="html">The view's current HtmlHelper instance.</param>
		/// <param name="item">The CSS class name of the icon to be displayed (for example, to display the star icon
		/// use fa-star).</param>
		/// <param name="classAttributes">The custom attributes to be added to the icon.</param>
		/// <returns></returns>
		public static MvcHtmlString Glyphicons(this HtmlHelper html, string item, params string[] classAttributes)
		{
			if (html == null) throw new ArgumentNullException("html");
			if (string.IsNullOrEmpty(item)) throw new ArgumentNullException("item");
			Glyphicon font = new Glyphicon("Custom", item);
			font.MergeClassAttributes(classAttributes);
			return font.Html;
		}
	}
}
